package com.oa.pm.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.core.PageResult;
import com.oa.core.utils.request.RFormParam;
import com.oa.pm.dto.EmploymentRecordListDTO;
import com.oa.pm.entity.EmploymentRecord;
import com.oa.pm.mapper.EmploymentRecordMapper;
import com.oa.pm.service.IEmploymentRecordService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.oa.pm.vo.EmploymentRecordListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

/**
 * <p>
 * 任职记录表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-01-22
 */
@Service
public class EmploymentRecordServiceImpl extends ServiceImpl<EmploymentRecordMapper, EmploymentRecord> implements IEmploymentRecordService {

    private final EmploymentRecordMapper employmentRecordMapper;

    @Autowired
    public EmploymentRecordServiceImpl(EmploymentRecordMapper employmentRecordMapper) {
        this.employmentRecordMapper = employmentRecordMapper;
    }

    @Override
    @CommonService
    public PageResult<EmploymentRecord> findList(Integer pageNum, Integer pageSize) {
        if(pageNum == null){
            List<EmploymentRecord> list = employmentRecordMapper.findList();
            return new PageResult<>(list);
        }else{
            // 当前页，总条数 构造 page 对象
            Page<EmploymentRecord> page = new Page<>(pageNum, pageSize);
            //查询
            List<EmploymentRecord> list = employmentRecordMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
    * 根据id查询
    */
    @Override
    @CommonService
    public EmploymentRecord findEmploymentRecordById(String id){
        return employmentRecordMapper.findById(id);
    }

    @Override
    public PageResult<EmploymentRecordListVO> findEmploymentRecordList(EmploymentRecordListDTO employmentRecordListDTO) {
        // 当前页，总条数 构造 page 对象
        return new PageResult<>(employmentRecordMapper.findEmploymentRecordList(employmentRecordListDTO.getPage(), employmentRecordListDTO));
    }
}
